/** 
 * @author seeker910
 * @description redjs javascript sdk :cms-api.js
 * @description 网站相关api 接口
 */

var cmsHost = {
    text: 'CMS C端服务',
    name: 'cms',
    url: 'http://localhost:12847/',
    index: 'dev/index',
    isLoaded: false,
    useSSL: false,
    controllers: [
        { name: 'news', path: 'news', GetDescription: 'GetDes' },
        { name: 'blog', path: 'blog', GetDescription: 'GetDes' },
        { name: 'interact', path: 'interact', GetDescription: 'GetDes' },
        { name: 'content', path: 'content', GetDescription: 'GetDes' },
    ]
};
var apiConfig = [
    {
        "group": "cms.new",
        "errorHandler": Rsd.app.httpRequestErrorHandler,
        "failureHandler": "failureHandler",
        "successHandler": null,
        "api": [
            {
                "name": "download",
                "failureHandler": "uploadFailHandler",
                "successHandler": "uploadSccessHandler",
                "method": "POST",
                //timeout:10000
            }

        ]
    },

];
/**
* 加载api services
*/
Rsd.loadServices(cmsHost, [], function (data, state) {
    if (state == 'serviceLoaded') {
        rsd.app.fire('cms-api', data);
    }
});
//缓存数据
$app.cms = $app.cms || {};

/**
 * 提交订阅
 * @param {*} data 
 */
$app.cms.submitSubscribe = function submitSubscribe(data, callback) {
    if (Rsd.isEmpty(data['subject'])) {
        Rsd.msg('The subject field is required.');
        return false;
    } 
    $app.submitData("cms.interact.subscribe", data, callback);
}
/**
 * 提交联系我们信息
 * @param {*} data 
 */
$app.cms.submitContact = function submitContact(data, callback) {
    
    if (Rsd.isEmpty(data['company'])) {
        Rsd.msg('The company field is required.');
        return false;
    }
    if (Rsd.isEmpty(data['name'])) {
        Rsd.msg('The name field is required.');
        return false;
    }
    if (Rsd.isEmpty(data['email'])) {
        Rsd.msg('The email field is required.');
        return false;
    }
    if (Rsd.isEmpty(data['phone'])) {
        Rsd.msg('The phone field is required.');
        return false;
    }
    if (Rsd.isEmpty(data['message'])) {
        Rsd.msg('The message field is required.');
        return false;
    }
    $app.submitData("cms.interact.contact", data, callback);
}
/**
 * 全文搜索
 * @param {*} data 
 */
$app.cms.submitSearch = function submitSearch(data, callback) {
    $app.submitData("cms.search.text", data, callback);//
}
